package com.cjm.one.controller.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.order.dto.OrderOperateDTO;
import com.cjm.one.model.order.dto.OrderStatusDto;
import com.cjm.one.model.order.enums.OrderParamsTypeEnum;
import com.cjm.one.model.order.enums.OrderStatusEnum;
import com.cjm.one.model.order.vo.OrderInfoVo;
import com.cjm.one.service.OrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "订单", description = "订单")
@RequestMapping("/api/order/info")
public class OrderInfoController {
    @Resource
    private OrderInfoService orderInfoService;
    @GetMapping("/list")
    @Operation(summary = "用户订单信息列表")
    Result<Page<OrderInfoVo>> list(@RequestParam(value = "current", defaultValue = "1") Long current,
                                   @RequestParam(value = "size", defaultValue = "10") Long size ,
                                   @RequestParam(value = "type", required = false) OrderParamsTypeEnum type){
        return orderInfoService.list(current, size, type);
    }
    @PostMapping("/add")
    @Operation(summary = "添加订单")
    Result<String> add(@RequestBody OrderOperateDTO orderOperateDTO){
        return orderInfoService.add(orderOperateDTO);
    }

    @PostMapping("/update")
    @Operation(summary = "更新订单")
    Result<Boolean> update(@RequestBody OrderInfoVo orderInfoVo){
        return orderInfoService.updateById(orderInfoVo);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除订单")
    Result<Boolean> appdelete(@PathVariable Long id){
        return orderInfoService.removeById(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询订单")
    Result<OrderInfoVo> getAppUserByOrderId(@PathVariable Long id){
        return orderInfoService.getAppUserByOrderId(id);
    }
    @PostMapping("/update/status")
    @Operation(summary = "更新订单")
    Result<Boolean> updateOrderStatus(@RequestBody OrderStatusDto orderStatusDto){
        return orderInfoService.updateOrderStatusById(orderStatusDto);
    }


}
